package com.glasses.business.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.glasses.business.R;
import com.glasses.business.appliction.MyApplication;
import com.glasses.business.base.AppBaseFragment;
import com.glasses.business.entity.MsgDetail;
import com.glasses.business.event.BussEvent;
import com.glasses.business.http.NetUtils;
import com.glasses.business.utils.Tools;

import net.neiquan.okhttp.NetCallBack;
import net.neiquan.okhttp.ResultModel;

import org.haitao.common.utils.AppLog;
import org.haitao.common.utils.ToastUtil;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import de.greenrobot.event.EventBus;

/**
 * Author:Dandy
 * Date:2016/12/7
 */

public class MsgDetailFragment extends AppBaseFragment {
    @InjectView(R.id.nickName)
    TextView nickName;
    @InjectView(R.id.industry)
    TextView industry;
    @InjectView(R.id.content)
    TextView content;
    private int id = 0;
    private MsgDetail msgDetail;

    @Override
    public int getRootViewId() {
        return R.layout.fragment_msg_detail;
    }

    @Override
    public void setViews() {
        setTitleTv("消息");
    }

    @Override
    public void initData() {
        if (getArguments() != null) {
            id = getArguments().getInt("id");
            Tools.showDialog(getActivity());
            NetUtils.getInstance().msgDetail(id, new NetCallBack() {

                @Override
                public void onSuccess(String response, String mssage, ResultModel model) {
                    Tools.dismissWaitDialog();
                    ToastUtil.shortShowToast(mssage);
                    msgDetail = ((MsgDetail) model.getModel());
                    if (msgDetail != null) {
                        nickName.setText(msgDetail.getTitle());
                        content.setText(msgDetail.getContent());
                        industry.setText(msgDetail.getTime());
                    }
                    MyApplication.getInstance().jpush=false;
                    EventBus.getDefault().post(new BussEvent(BussEvent.JPush));
                }

                @Override
                public void onFail(boolean dataError, int errorCode, String mssage) {
                    Tools.dismissWaitDialog();
                    ToastUtil.shortShowToast(mssage);
                }
            }, MsgDetail.class);
        }
    }

    @Override
    public boolean mainTabShow() {
        return false;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.inject(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }
}
